﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Robot_1;

namespace FieldNS
{
    public class Field
    {
        protected static int origRow;
        protected static int origCol;
        protected int x;
        protected int y;

        public Field(int x0, int y0, int heght, int width)
        {
            origRow = y0;
            origCol = x0;
            y = width;
            x = heght;
            makeField(x, y);
        }

        public static void WriteAt(string s, int x, int y)
        {
            try
            {
                Console.CursorVisible = false;
                Console.SetCursorPosition(origCol + x, origRow + y);
                Console.Write(s);
            }
            catch (ArgumentOutOfRangeException e)
            {
                Console.Clear();
                Console.WriteLine(e.Message);
            }
        }
        protected void makeField(int x, int y)
        {
            // Clear the screen, then save the top and left coordinates.
            Console.Clear();
            origRow = Console.CursorTop;
            origCol = Console.CursorLeft;
            int yMax = y;
            int xMax = x;


            // Draw the left side of a xMax x yMax rectangle, from top to bottom.
            WriteAt("+", 0, 0);
            for (int i = 1; i < yMax; i++)
            {
                WriteAt("|", 0, i);
            }
            WriteAt("+", 0, yMax - 1);

            // Draw the bottom side, from left to right.
            for (int i = 1; i < xMax; i++)
            {
                WriteAt("-", i, yMax - 1);
            }

            WriteAt("+", xMax - 1, yMax - 1);

            // Draw the right side, from bottom to top.
            WriteAt("+", xMax - 1, 0);
            for (int i = 1; i < yMax - 1; i++)
            {
                WriteAt("|", xMax - 1, i);
            }

            // Draw the top side, from right to left.
            for (int i = 1; i < xMax - 1; i++)
            {
                WriteAt("-", i, 0);
            }
        }


    }
}
